﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace 三维转台控制系统
{
    /// <summary>
    /// 定义单个轴的类
    /// </summary>
    public partial class Axis:ObservableObject
    {
        //轴名称
        [ObservableProperty]
        private string name;

        //轴当前位置
        [ObservableProperty]
        private double currentPosition;

        //轴位置偏置
        [ObservableProperty]
        private double positionOffset;

        //启用限位
        [ObservableProperty]
        private bool limitPositionEnable;

        //轴下限位
        [ObservableProperty]
        private double lowerLimitPosition;

        //轴上限位
        [ObservableProperty]
        private double upperLimitPosition;


        //轴当前速度
        [ObservableProperty]
        private double currentSpeed;

        //轴当前速度
        [ObservableProperty]
        private double currentAcceleration;

        //轴使能状态
        [ObservableProperty]
        private bool enableState;

        //轴故障状态
        [ObservableProperty]
        private bool errorState;

        //轴下限位状态
        [ObservableProperty]
        private bool lowerLimitState;

        //轴上限位状态
        [ObservableProperty]
        private bool upperLimitState;


        //轴设置位置
        [ObservableProperty]
        private double setPosition;

        //轴设置速度
        [ObservableProperty]
        private double setSpeed;

        //轴设置加速度
        [ObservableProperty]
        private double setAcceleration;


        //轴图表中显示点的数量
        [ObservableProperty]
        private int pointCount=30;

        //在图表中显示运动状态的点
        [ObservableProperty]
        private ObservableCollection<MoveState> points=new ObservableCollection<MoveState>();

        //向图表中添加一点
        public void AddPoint(MoveState MoveState)
        {
            if(Points.Count >= PointCount) 
            {
                //前移一项
                for(int i=0; i<Points.Count-1; i++)
                {
                    Points[i] = Points[i + 1];
                }
                Points[PointCount-1] = MoveState;
            }
            else
            {
                Points.Add(MoveState);
            }
        }

    }
    public partial class MoveState:ObservableObject
    {
        [ObservableProperty]
        private string time;

        [ObservableProperty]
        private double position;

        [ObservableProperty]
        private double speed;

        [ObservableProperty]
        private double acceleration;
    }
}
